package com.e5.training.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.e5.training.domain.User;
import com.e5.training.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UserSaveAction extends ActionSupport implements ModelDriven<Object>{

	private User user = new User();
	
	@Autowired
	private UserService userService;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		String flag = null;
		try 
		{
			if(user != null)
			{
				userService.editUser(user);
				flag = "success";
			}
			else
			{
				flag = "failure";
				System.out.println("The action is failure");
			}
		}
		catch (Exception e) 
		{
			// TODO: handle exception
			flag = "failure";
		}
		return flag;
	}



	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return user;
	}

}
